package base.controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class LoginChecker extends HttpServlet {

    private static Log log = LogFactory.getLog(LoginChecker.class);
    private static final String NONMEMBER_PAGE = "";
    private static final String MEMBER_PAGE = "/WEB-INF/views/memberView.jsp";
    private static final String LOGIN_PAGE = "/welcome.jsp";
    private static final String ERROR_PAGE = "";

    // private AuthenticationObj;

    public void doPost(HttpServletRequest request, HttpServletResponse response) {

	String account = request.getParameter("account");
	String password = request.getParameter("password");

	if (StringUtils.isBlank(account) || StringUtils.isBlank(password)) {
	    try {
		request.setAttribute("warningMess",
			"Please input correct Account/Password");
		RequestDispatcher requestDispatcher = request
			.getRequestDispatcher(LOGIN_PAGE);
		requestDispatcher.forward(request, response);
	    } catch (ServletException e) {
		log.error(ExceptionUtils.getFullStackTrace(e));
	    } catch (IOException e) {
		log.error(ExceptionUtils.getFullStackTrace(e));
	    }
	} else {
	    doAuthenticate(account, password);
	}
    }

    private void doAuthenticate(String account, String password) {

    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) {
	doPost(request, response);
    }
}
